package com.example.blogdemo.repository;

import com.example.blogdemo.entity.LoginTicket;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;


/**
 * @Author Anita
 * @Date 2017/12/13 11:57
 */
public interface LoginTicketRepository extends JpaRepository<LoginTicket, Integer> {

    public LoginTicket findById(Integer id);

    public LoginTicket findByTicket(String ticket);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update login_ticket l set l.status =?1 where l.ticket = ?2",nativeQuery = true)
    public void updateStatusByTicket(Integer status,String ticket);

    @Transactional
    @Modifying
    @Query(value = "delete from login_ticket where id = :id",nativeQuery = true)
    public void deleteById(@Param("id") Integer id);

}
